package com.datetest;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;

public class DateTest {
    /**
     * 本月的任意一天
     */
    static SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
    public static void main(String[] args) {
        //本周的最后一天
        Calendar todayEnd = Calendar.getInstance();
        todayEnd.setTimeZone(TimeZone.getTimeZone("GMT+20"));
        todayEnd.setFirstDayOfWeek(Calendar.MONDAY);
        todayEnd.setMinimalDaysInFirstWeek(Calendar.MONDAY);
        todayEnd.set(Calendar.DAY_OF_WEEK, 8);
        todayEnd.set(Calendar.HOUR, 23);
        todayEnd.set(Calendar.MINUTE, 59);
        todayEnd.set(Calendar.SECOND, 59);
        todayEnd.set(Calendar.MILLISECOND, 999);
        System.out.println(todayEnd.getTimeInMillis() - System.currentTimeMillis());
        Calendar start = Calendar.getInstance();
        start.set(Calendar.DAY_OF_MONTH, 23);
        System.out.println(sdf.format(start.getTime()));

        /**
         * 本月的最后一天
         */
        Calendar end = Calendar.getInstance();
        end.set(Calendar.DAY_OF_MONTH, 1);
        end.roll(Calendar.DAY_OF_MONTH, -1);
        end.set(Calendar.HOUR_OF_DAY, 23);
        end.set(Calendar.MINUTE, 59);
        end.set(Calendar.SECOND, 59);
        System.out.println(sdf.format(end.getTime()));
        //获取下月的第一天
        Calendar cal1 = Calendar.getInstance();
        cal1.add(Calendar.MONTH, 1);
        System.out.println(sdf.format(cal1.getTime()));
    }

}
